<template>
  <el-row type="flex" justify="center" align="middle">
    <el-col :span="6">
      <el-form label-width="60px" :rules="loginRules" :model="loginform" ref="ruleForm">
        <div style=" vertical-align: middle; text-align: center;">
          <h2 class="">用户登录</h2>
          <el-form-item prop="selectedOption">
            <el-select v-model="loginform.selectedOption" placeholder="请选择登录平台">
              <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="username">
            <el-input class="rounded-input" v-model="loginform.username" clearable placeholder="用户"
                      prefix-icon="el-icon-user"></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input class="rounded-input" v-model="loginform.password" show-password clearable placeholder="密码"
                      prefix-icon="el-icon-lock"></el-input>
          </el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
        </div>


      </el-form>
    </el-col>
  </el-row>
</template>

<script>

export default {
  data() {
    return {
      options: [{
        value: 1,
        label: '平台用户登录'
      }, {
        value: 2,
        label: '核心企业用户登录'
      }, {
        value: 3,
        label: '融资企业用户登录'
      }],
      loginform: {
        username: "",
        password: "",
        selectedOption: "",
      },
      loginRules: {
        selectedOption: [
          {required: true, message: '请选择选项', trigger: 'change'}
        ],
        username: [
          {required: true, message: "请输入用户名", trigger: "blur"},
          {min: 3, max: 100, message: "长度在 3 到 100 个字符", trigger: "blur"}
        ],
        password: [
          {required: true, message: "请输入密码", trigger: "blur"},
          {min: 2, max: 15, message: "长度在 2 到 15 个字符", trigger: "blur"}
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.loginform.selectedOption)
          let param = new URLSearchParams();
          param.append('username', this.loginform.username)
          param.append('password', this.loginform.password)
          this.$axios({
            url: '/api/login',
            method: 'post',
            data: param
          }).then(res => {
            console.log(res.data)
            if (res.data.code == 200) {
              localStorage.setItem('jwt', res.data.data)
              localStorage.setItem('userName', this.loginform.username)
              sessionStorage.setItem('userName', this.loginform.username)
              if (this.loginform.selectedOption == 1) {
                this.$router.push('platformhome')
              }
              if (this.loginform.selectedOption == 2) {
                this.$router.push('coreHome')
              }
              if (this.loginform.selectedOption == "3") {
                this.$router.push('financeHome')
              }
            } else {
              alert(2000);
            }
          })


          //     this.$message({
          //   message: '恭喜你，这是一条成功消息',
          //   type: 'success'
          // });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
}
</script>
<style  scoped>
.el-row {
  background-image: url("../assets/login/login.jpg");
  background-size: 100% 100%;
  height: 100%;
}

.el-col {
  background-color: rgba(76, 39, 39, 0.46);
  padding-top: 35px;
  border-radius: 30px;
  width: 450px;
  height: 350px;
}

.rounded-input {
  width: 250px;
  margin-top: 15px;

}

.rounded-input >>> .el-input__inner {
  border-radius: 15px; /* 调整圆角大小，根据需要进行修改 */
  color: #f8f6f4;
}

.el-button {
  width: 250px;
  border-radius: 15px;
  margin-top: 15px;
  background: #bbec8a;
}

.el-select {
  width: 250px;
  border-radius: 15px;
  margin-top: 15px;
}

.el-select >>> .el-input__inner {
  border-radius: 15px; /* 调整圆角大小，根据需要进行修改 */
}

.el-form-item {
  padding: 0;
  margin-right: 60px;
  margin-top: 0px;
  margin-top: 0;
  margin-bottom: 0;
}
.el-input__inner{
  background: transparent ;
}
/*// 改变input里的字体颜色*/
/deep/input::-webkit-input-placeholder {
  color: #0c0b0b;
  font-size: 15px;
}

/*// 改变input框背景颜色*/
/deep/.el-input__inner {
  background-color: transparent !important;
  border: 1px solid #0c1011;
}

</style>

